package com.lty.jeeg.server.modules.tms.controller;

import com.lty.jeeg.server.common.dto.ResponseInfo;
import com.lty.jeeg.server.common.utils.ResponseUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lty.jeeg.server.common.page.table.PageTableRequest;
import com.lty.jeeg.server.common.page.table.PageTableResponse;

import com.lty.jeeg.server.modules.tms.model.Matters;
import com.lty.jeeg.server.modules.tms.service.MattersService;

import io.swagger.annotations.ApiOperation;

/**
 * @author : LTY
 * @date : 2019-04-03 15:00:28
 * Description : 
 */
@Api(tags = "任务动态")
@RestController
@RequestMapping("/matters")
public class MattersController {

    private final MattersService mattersService;

    @Autowired
    public MattersController(MattersService mattersService) {
        this.mattersService = mattersService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public ResponseInfo get(@PathVariable Long id) {
        return ResponseUtil.success(mattersService.getById(id));
    }

    @PostMapping
    @ApiOperation(value = "保存")
    public ResponseInfo save(@RequestBody Matters matters) {
        return ResponseUtil.success(mattersService.save(matters));
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public ResponseInfo update(@RequestBody Matters matters) {
        return ResponseUtil.success(mattersService.update(matters));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public ResponseInfo delete(@PathVariable Long id) {
        return ResponseUtil.success(mattersService.delete(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return mattersService.list(request);
    }

    @GetMapping("/listAll/{taskId}")
    @ApiOperation("获取某任务的全部动态")
    public ResponseInfo listAll(@PathVariable("taskId") Long taskId) {
        return ResponseUtil.success(mattersService.listAll(taskId));
    }

}
